var { textUtils, randomUtils, logUtils } = require("../../utils/index");
var adCommon = require("../adCommon");
var adType1 = require("./adType1");
var MAX_AD_INTERVAL = 45;
module.exports = {
  startWatchAd(maxAdCount) {
    adCommon.adCount = 0;
    adCommon.maxAdCount = maxAdCount || 5;
    this.getAdType();
  },
  getAdType() {
    var span = randomUtils.getRandom(MAX_AD_INTERVAL, MAX_AD_INTERVAL + 5);
    for (var index = 0; index < 5; index++) {
      var contents = ["秒后领取奖励", "后可领取奖励", "完成任务"];
      var TextUI = textUtils.existsOneTextEndsWith(contents);
      if (TextUI) {
        logUtils.info("发现广告:", TextUI.text());
        adType1.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      sleep(2 * 1000);
    }
    logUtils.info("adBaiDu", "未知的adType");
  },
};
